package com.funny.spel;

import org.springframework.expression.EvaluationContext;
import org.springframework.expression.ExpressionParser;
import org.springframework.expression.common.TemplateParserContext;
import org.springframework.expression.spel.standard.SpelExpressionParser;
import org.springframework.expression.spel.support.StandardEvaluationContext;

/**
 * @author fanxiao  2022/4/8
 * @since 1.0.0
 */
public class AppStarter {

  public static void main(String[] args) {
	  //
	  ExpressionParser expressionParser = new SpelExpressionParser();

	  EvaluationContext context = new StandardEvaluationContext();
	  User user = new User();
	  user.setId(1);
	  user.setName("Tommy");
	  context.setVariable("id",user.getId());
	  context.setVariable("name", user.getName());
    System.out.println(
        expressionParser
            .parseExpression("您好，#{#id}, #{#name}", new TemplateParserContext())
            .getValue(context));
  }
}
class User {
	private int id;

	private String name;

	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}
}